package com.example.blogdesign.Controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.example.blogdesign.Entity.Blog;
import com.example.blogdesign.Service.IBlogService;
import com.example.blogdesign.dto.Result;
import com.example.blogdesign.dto.UserDTO;
import com.example.blogdesign.utils.SystemConstants;
import com.example.blogdesign.utils.UserHolder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/blog")
public class BlogController {

    @Resource
    private IBlogService blogService;

    //保存博客并推送
    @PostMapping("/save")
    public Result<Long> saveBlog(@RequestBody Blog blog) {
        return blogService.saveBlog(blog);
    }

    //博客点赞
    @PutMapping("/like/{id}")
    public Result<?> likeBlog(@PathVariable("id") Long blogId) {
        return blogService.likeBlog(blogId);
    }

    //获取当前用户发布的博客(分页)
    @GetMapping("/of/me")
    public Result<List<Blog>> queryMyBlog(@RequestParam(value = "current", defaultValue = "1") Integer current) {
        return blogService.queryMyBlog(current);
    }

    //查询热门博客根据点赞数量排行
    @GetMapping("/hot")
    public Result<List<Blog>> queryHotBlog(@RequestParam(value = "current", defaultValue = "1") Integer current) {
        return blogService.queryHotBlog(current);
    }

    //删除博客
    @DeleteMapping("/delete")
    public Result<?> deleteBlog(@RequestParam("id") Long blogId){
        return blogService.deleteBlogById(blogId);
    }



}
